import service from "@/service";

/**
 * 获取书签列表
 * @param {*} uid 
 * @returns 
 */
export function getBookmarks(village, uid) {
    let community = 'YSHY';
    if (village == '杏园小区') {
        community = "XYXQ";
    } else if (village == "湖口小区") {
        community = "HKXQ"
    }
    return service({
        url: `/bookmark/get?user_id=${uid}&community=${community}`,
        method: 'GET'
    })
}
/**
 * 删除书签
 * @param {*} id  书签ID
 */
export function delBookmark(id) {
    return service({
        url: `/bookmark/delete`,
        method: 'POST',
        data: {
            id: id
        }
    })
}

/**
 * 添加书签
 * @param {*} uid 用户ID
 * @param {*} name 书签名称
 * @param {*} info 相机信息
 */
export function addBookmark(village, uid, name, info) {
    // location[0,1,2]=x,y,z
    // rotation[0, 1, 2] = roll yaw pitch
    let location = info.location;
    let rotation = info.rotation;
    let community = 'YSHY';
    if (village == '杏园小区') {
        community = "XYXQ";
    } else if (village == "湖口小区") {
        community = "HKXQ"
    }
    let param = {
        community: community,
        name: name,
        userID: uid,
        x: "" + location[0],
        y: "" + location[1],
        z: "" + location[2],
        roll: "" + rotation[0],
        yaw: "" + rotation[1],
        pitch: "" + rotation[2]
    }
    if (community && uid) {
        return service({
            url: `/bookmark/post`,
            method: 'POST',
            data: param
        })
    }
}
/**
 * 下载模拟报告
 * @param {*} tablename 
 * @returns 
 */
export function downloadReport(tablename) {
    return service({
        url: `/sim/report`,
        method: 'POST',
        responseType: "blob",
        data: {
            "name": tablename
        }
    })
}
/**
 * 下载模拟数据
 * @returns 
 */
export function downloadExcel(tablename) {
    return service({
        url: `/sim/excel`,
        method: 'POST',
        responseType: "blob",
        data: {
            "name": tablename
        }
    })
}
/**
 * 从配置文件中读取各个小区的人口数量
 * @returns 
 */
export function getPopulation() {
    let index = window.location.pathname.lastIndexOf('/');
    let path = ""
    if (index != 0) {
        path = window.location.pathname.substring(0, index);
    }
    return service({
        baseURL: `${window.location.origin}`,
        url: `${path}/population.json`,
        method: 'GET'
    })
}